package com.ycd.Servlet;


import com.ycd.Entity.UserEntity;
import com.ycd.Service.UserEntityService;

import com.ycd.Service.impl.UserEntityServiceImpl;
import com.ycd.Util.MD5Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description 修改用户
 * @Author ycd
 * @Date : 2022/3/18 16:58
 * @Version : 1.0
 */
@WebServlet("/updateUser")
public class AmendUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //规范字符集
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        String userName =req.getParameter("userName");
        String userPwd = req.getParameter("userPwd");
        String  id=req.getParameter("id");


        UserEntityService userEntityService=new UserEntityServiceImpl();


        if (userPwd != null && userName != null) {

            UserEntity userentity = new UserEntity();
            userentity.setId(Integer.parseInt(id));
            userentity.setName(userName);
            userentity.setPwd(MD5Util.toMD5(userPwd));
            userEntityService.updateUser(userentity);

            resp.sendRedirect("AccountManagement.html");
        }
        }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
